function f = oneFactorModel(Params, Model)

data = Model.Data;
name = Model.Name;
ret = data(2:end) - data(1:end-1);
R_t_1 = data(1:end-1);

switch(name)
    
    case 'lognormal'
        alpha_1 = Params(1);
        sigma = Params(2);        
        mean = alpha_1.*R_t_1;
        volatility = sigma.*R_t_1;        
    case 'dothan'
        mean = 0;
        sigma = Params(1);
        volatility = sigma.*R_t_1;
    case 'pureCEV'
        mean = 0;
        sigma = Params(1);
        rho = Params(2);
        volatility = sigma.*(R_t_1.^rho);
    case 'Vasicek'
        alpha_0 = Params(1);
        alpha_1 = Params(2);
        sigma = Params(3);
        mean = alpha_0 + alpha_1*R_t_1;
        volatility = sigma;
    case 'CIR'
        alpha_0 = Params(1);
        alpha_1 = Params(2);
        sigma = Params(3);
        mean = alpha_0 + alpha_1*R_t_1;
        volatility = sigma.*sqrt(R_t_1);
    case 'CKLS'
        alpha_0 = Params(1);
        alpha_1 = Params(2);
        sigma = Params(3);
        rho = Params(4);
        mean = alpha_0 + alpha_1*R_t_1;
        volatility = sigma.*(R_t_1.^rho);
    case 'nonlinear'
        alpha = Params(1);
        alpha_0 = Params(2);
        alpha_1 = Params(3);
        alpha_2 = Params(4);
        sigma = Params(5);
        rho = Params(6);
        mean = alpha./R_t_1 + alpha_0 + alpha_1.*R_t_1 + alpha_2.*R_t_1.^2;
        volatility = sigma.*(R_t_1.^rho);
    otherwise                       % RW by default                
        alpha_0 = Params(1);
        sigma = Params(2);        
        mean = alpha_0;  
        volatility = sigma;
end

% % normal MLE

if(Model.predictDay==0)
    normPDF = normpdf(ret,mean,volatility);
    logpdf = log(normPDF);
    f = logpdf;
else
    resR = zeros(Model.predictDay,1);
    resR(1) = data(end);
    epsilon = normrnd(0,1,[Model.predictDay 1]);
    for i = 1:Model.predictDay-1
        switch(name)
            case 'lognormal'
            case 'dothan'
            case 'RW'
            case 'CIR'
                resR(i+1,1) = resR(i,1) + alpha_0 + alpha_1.* resR(i,1) +  epsilon(i) .* sigma.*sqrt(resR(i,1));
            case 'Vasicek'
                resR(i+1,1) = resR(i,1) + alpha_0 + alpha_1.* resR(i,1) +  epsilon(i) .* sigma;
            case 'CKLS'
                resR(i+1,1) = resR(i,1) + alpha_0 + alpha_1.* resR(i,1) +  epsilon(i) .* sigma.*(resR(i,1).^rho);
            case 'nonlinear'
        
    end
    f= resR;
end



% Robust M-estimator proposed by Huber (1981)
% a = 2; %robust parameter: a between [1;3]
% robustPDF = robustMEsimator(ret,mean,volatility,a);
% logpdf = log(robustPDF);

% f = sum(logpdf);

end